home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / fr_may92.zip / FREQ.ASM < prev    next >
Assembly Source File  |  1992-05-04  |  15KB  |  453 lines

  1. ; FREQ.ASM --- TSR source for frequency logger.
  2. ;
  3. ;make file with turbo asm and linker:
  4. ;tasm freq.asm,,nul,nul;
  5. ;tlink /t freq,,nul,;
  6. ;
  7. ; make file with masm, link, exe2bin:
  8. ; masm freq.asm,,nul,nul;
  9. ; link freq,,nul,;
  10. ; exe2bin freq.exe freq.com
  11. ; del freq.exe
  12. ;
  13. ;Purpose: Maintains last access date and time for selected directories
  14. ;         of files. The file name, time and date are stored as normal
  15. ;         directory entries. The directory entries have 0 file
  16. ;         length and reside one level deeper in the directory tree,
  17. ;         inside a subdirectory with special name FREQ.USE.
  18. ;
  19. ;Use:     Create the subdirectory FREQ.USE inside a given subdirectory
  20. ;         (there will ultimately be many with this same name). Use the
  21. ;         DOS command MKDIR. This action determines which subdirectories
  22. ;         receive updates. No subdirectory FREQ.USE means no update takes
  23. ;         place. After loading the TSR, the updates to the subdirectories
  24. ;         are automatic, across all disks, even floppies.
  25. ;
  26. ;         Before doing a file entry update, the directory entry is
  27. ;         checked to see if it already exists. If so, then it is further
  28. ;         checked for file length 0. If either it fails to exist, or it
  29. ;         does exist with length 0, then the directory entry is created
  30. ;         with the system time and date and file length 0.
  31. ;
  32. ;         If the TSR is not loaded, then no updates take place. The
  33. ;         updates occur exactly when the TSR is loaded.
  34. ;
  35. ;         File names in the FREQ.USE subdirectories are normal in every
  36. ;         way: all DOS commands apply, including especially DIR and DEL.
  37. ;
  38. ;Version: 30 November 1991
  39. ;Authors: Grant B. Gustafson for the current version. Similar version
  40. ;         using files was developed by Greg Conner and Grant Gustafson.
  41. ;         Other authors will be added here as contributions are made.
  42. ;email:   gustafso@math.utah.edu.Internet
  43. ;Copyright:
  44. ;         The source code is jointly owned by the authors. It may be used
  45. ;         for educational purposes without limitation. Modified versions
  46. ;         of the sources are considered private copies and should bear
  47. ;         the new authors names.
  48. ;Responsibility:
  49. ;         This computer program is used at your own risk. If you use it,
  50. ;         then you assume responsibility for anything that happens as a
  51. ;         result of the program operation, including but not limited to
  52. ;         programming errors, faulty operation, file system destruction.
  53. ;         The authors are not responsible.
  54. ;
  55. Cseg      segment public para
  56.           assume  cs:Cseg, ds:nothing, es:nothing, ss:nothing
  57.  
  58.           org     080H
  59. cmdline   label   byte                 ;pointer to command line
  60.  
  61.           org     100H
  62. comentry: jmp     init
  63.  
  64.  
  65. ;previous interrupt handlers
  66.         even
  67. dos_int        label dword
  68. old21          dw 2 dup (?)            ;old int21 vector
  69. ;***********************************************************************
  70. ;interrupt handler for int21
  71. newint21 proc  near
  72.          assume ds:nothing
  73.         pushf                  ;save flags
  74.         push    si
  75.         mov     si,offset fn            ;are we to ignore updates?
  76.         cmp     byte ptr cs:[si],1
  77.         pop     si
  78.         jne     ex21
  79.         cmp     ax,'fr'                 ;check for install twice
  80.         jne     ex20
  81.         popf                            ;tried to install twice
  82.         xor     ax,ax                   ;clear flags
  83.         mov     ax,'eq'                 ;return code for install
  84.         iret                            ;return from interrupt
  85. ex20:
  86.         cmp     ah,3dh
  87.         jne    ex21
  88.         call   update          ;update dir entry
  89. ex21:   popf
  90.         jmp    (dos_int)       ;transfer to previous int21 vector
  91. newint21 endp
  92.  
  93. ;******************************************************************************
  94. ;resident data section follows
  95. ;******************************************************************************
  96.  
  97.  
  98.         even
  99. ;temporary stack used by interrupt handler
  100. newss          dw      0               ;segment of our temporary stack
  101. newsp          dw      0               ;initial stack pointer
  102.  
  103. ;information saved about the calling program
  104. oldss          dw      ?               ;stack segment
  105. oldsp          dw      ?               ;stack pointer
  106.  
  107.  
  108. ;***********************************************************************
  109. ;update dir entry in ..\freq.use subdirectory.
  110.  
  111. update proc  near
  112.        assume ds:nothing
  113.  
  114. ;save current stack
  115.        mov     oldss,ss
  116.        mov     oldsp,sp
  117.  
  118. ;switch to our stack
  119.        cli
  120.        mov     ss,newss
  121.        mov     sp,newsp
  122.        sti
  123.  
  124. ;store registers
  125.        push    ax
  126.        push    bx
  127.        push    cx
  128.        push    dx
  129.        push    si
  130.        push    di
  131.        push    es
  132.        push    ds
  133.  
  134.         call    makefilename            ;make up new filename in FILEN
  135.         call    openfile                ;test nonexistent or filelen=0
  136.         cmp     ax,0                    ;returns 0 if not Ok to create
  137.         jz      quit
  138.         call    createfile              ;create file and close it.
  139. quit:
  140. ;restore registers
  141.        pop     ds
  142.        pop     es
  143.        pop     di
  144.        pop     si
  145.        pop     dx
  146.        pop     cx
  147.        pop     bx
  148.        pop     ax
  149.  
  150. ;restore stack
  151.        cli
  152.        mov     ss,oldss
  153.        mov     sp,oldsp
  154.        sti
  155.  
  156.        ret
  157. update endp
  158.  
  159. openfile proc near
  160. ; FILEN=filename
  161. ; see if file exits. If so, see if it is 0 bytes long.
  162.  
  163.         assume ds:nothing
  164. ; open the file
  165.         mov     ax,cs
  166.         mov     ds,ax           ;ds=code segment at interrupt time
  167.         mov     dx,offset FILEN ;file name 0 terminated
  168.         mov     al,0            ;read only
  169.         mov     ah,3dh          ;open file
  170.         mov     si,offset fn    ;turn off ah=3dh trigger in newint21!
  171.         mov     byte ptr ds:[si],0
  172.         int     21h
  173.         mov     bx,ax           ;bx=file handle
  174.         mov     si,offset fn    ;turn on trigger again.
  175.         mov     byte ptr ds:[si],1
  176.         mov     ax,1            ;return ax=1 if ok to create file
  177.         jc      stop            ;ok to create it, file not found
  178.         push    bx
  179.         mov     cx,1            ;read one byte
  180.         mov     ax,cs
  181.         mov     ds,ax           ;ds=code segment at interrupt time
  182.         mov     dx,offset BUFFER
  183.         mov     ah,3fh          ;read from file, handle=bx, bytes=cx
  184.         int     21h
  185.         pop     bx              ;handle=bx
  186.         push    ax
  187.         mov     ah,03eh         ;close file
  188.         int     21h
  189.         pop     ax
  190.         cmp     ax,0            ;read nothing?
  191.         mov     ax,1
  192.         jz      stop
  193.         mov     ax,0            ;return ax=0 to signal no create file
  194. stop:
  195.         ret
  196.  
  197. openfile endp
  198.  
  199. createfile proc near                    ;create dir entry
  200.          assume ds:nothing
  201.         mov     ax,cs                   ;with current time stamp
  202.         mov     ds,ax                   ;0 byte file (no space used)
  203.         mov     cx,0                    ;file attributes
  204.         mov     dx,offset FILEN         ;full path name to create
  205.         mov     ah,03ch                 ;create file
  206.         int     21h
  207.         jc      createfileexit
  208.         mov     bx,ax
  209.         mov     ah,03eh                 ;close file
  210.         int     21h
  211. createfileexit:
  212.         ret
  213. createfile endp
  214.  
  215.  
  216. strcopy proc near
  217. ;cx=count, ds:si=source, es:di=dest. Copy until cx==0 or [si]==0
  218. ;ah=last byte copied or 0 if none are copied.
  219.          assume ds:nothing
  220.         mov     ah,0
  221. strcopyloop:
  222.         cmp     cx,0
  223.         jz      strcopyquit
  224.         dec     cx
  225.         mov     al,byte ptr ds:[si]
  226.         mov     byte ptr es:[di],al
  227.         cmp     al,0
  228.         jz      strcopyquit
  229.         inc     si
  230.         inc     di
  231.         mov     ah,al
  232.         jmp     strcopyloop
  233. strcopyquit:
  234.         mov     byte ptr es:[di],0
  235.         ret
  236. strcopy endp
  237.  
  238. makefilename proc near
  239. ;ds:dx=filename input. Split off dir name, add FREQ.USE